package com.hfjyz.exam.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.hfjyz.exam.command.ModifyPasswordCommand;
import com.hfjyz.exam.service.LoginService;

public class ModifyPasswordController extends SimpleFormController {
	private LoginService loginService;

	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		ModifyPasswordCommand cmd = (ModifyPasswordCommand) command;
		if (!errors.hasErrors()) {
			loginService.modifyPassword(request, cmd, errors);
		}
		if (errors.hasErrors()) {
			return new ModelAndView(getFormView(), errors.getModel());
		} else {
			return new ModelAndView(getSuccessView(), errors.getModel());
		}
	}

	/**
	 * @return the loginService
	 */
	public LoginService getLoginService() {
		return loginService;
	}

	/**
	 * @param loginService
	 *            the loginService to set
	 */
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

}